
#include "../CASF/CDSF_ErrorCode.h"
#include "../CASF/CDSF_Tasks.h"
#include "../CASF/CDSF_Display.h"
#include "../CASF/CDSF_WatchDog.h"
#include "../CASF/CDSF_Control.h"
#include "../CASF/CDSF_Bus.h"
#include "../CASF/CDSF_Timer.h"
#include "../CASF/CDSF_AppInit.h"
/* #include <stdio.h> */

static SFCode task2Init(SFClockRate rate){
	return SFDisplayInit(rate);
}

static SFCode task2Work(void){
	/* printf("task2\n");fflush(stdout);*/
	return SFDisplayDelegate();
}

static SFCode task3Init(SFClockRate rate){
	return SFControlInit(rate);
}

static SFCode task3Work(void){
	/* printf("task3\n");fflush(stdout); */
	return SFControlDelegate();
}

static SFCode task4Init(SFClockRate rate){
	SFCode rt;
	rt = SFBusReadInit(rate);
	if(SFOK(rt))
		rt = SFBusWriteInit(rate);
	return rt;
}

static SFCode task4Work(void){
	SFCode rt;
	/* printf("task4\n");fflush(stdout); */
	rt = SFBusReadDelegate();
	if(SFOK(rt))
		rt = SFBusWriteDelegate();
	return rt;
}


/* ÏµÍ³(¸¨Öú)Ê±ÖÓÆµÂÊ */
static const int sysClockRate = 150;
static const int sysAuxClockRate = 150;

extern void ApplicationStart(){
	SFCode rt;
	
	printf("AppStart\n");
	
	SFAppAddTask(SFTaskTypeHard, "Watchdog", 25, 0, 0, SFWatchdogInit, SFWatchdogDelegate);
	SFAppAddTask(SFTaskTypeHard, "Timer", 25, 0, 0, SFTimerInit, SFTimerDelegate);
	SFAppAddTask(SFTaskTypeSoft, "Display", 25, 190, 10240, task2Init, task2Work);
	SFAppAddTask(SFTaskTypeSoft, "Control", 25, 188, 10240, task3Init, task3Work);
	SFAppAddTask(SFTaskTypeSoft, "Bus_A429", 75, 184, 10240, task4Init, task4Work);
	
	rt = SFAppStart(sysClockRate, sysAuxClockRate);
	
	if(SFError(rt)){
		printf("Error! Error Code = %i", rt);
	}
}

